package com.vegetable.modules.controller.baseData;


import com.alibaba.fastjson.JSON;
import com.vegetable.common.annotation.SysLog;
import com.vegetable.common.utils.PageUtils;
import com.vegetable.common.utils.R;
import com.vegetable.modules.controller.AbstractController;
import com.vegetable.modules.entity.baseData.VehicleManagement;
import com.vegetable.modules.service.baseData.IVehicleManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 车辆管理 前端控制器
 * </p>
 *
 * @author wangruijie
 * @since 2024-03-04
 */
@Slf4j
@RestController
@RequestMapping("/vehicleManagement")
@AllArgsConstructor
@Api(value = "车辆管理", tags = "车辆管理")
public class VehicleManagementController extends AbstractController {

    private IVehicleManagementService vehicleManagementService;
    /**
     * 所有车辆管理列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "条件查询车辆管理列表", notes = "条件查询车辆管理列表")
    public R list(@RequestParam Map<String, Object> params){
        log.info("条件查询车辆管理列表{}", JSON.toJSONString(params));
        PageUtils page = vehicleManagementService.queryPage(params);

        return R.data( page);
    }

    /**
     * 保存车辆管理
     */
    @SysLog(value = "保存车辆管理")
    @PostMapping("/save")
    @ApiOperation(value = "保存车辆管理", notes = "保存车辆管理")
    public R save(@RequestBody VehicleManagement vehicleManagement){
        vehicleManagement.setCreateUserId(getUserId());
        vehicleManagementService.save(vehicleManagement);
        return R.status(true);
    }

    /**
     * 修改车辆管理
     */
    @SysLog(value = "修改车辆管理")
    @PostMapping("/update")
    @ApiOperation(value = "修改车辆管理", notes = "修改车辆管理")
    public R update(@RequestBody VehicleManagement vehicleManagement){
        vehicleManagement.setCreateUserId(getUserId());
        vehicleManagementService.updateById(vehicleManagement);
        return R.status(true);
    }

    /**
     * 删除车辆管理
     */
    @SysLog(value = "删除车辆管理")
    @GetMapping("/delete")
    @ApiOperation(value = "删除车辆管理", notes = "删除车辆管理")
    public R delete(Long id){
        VehicleManagement vehicleManagement = vehicleManagementService.getById(id);
        if (vehicleManagement == null){
            return R.fail("查询不到数据");
        }
        vehicleManagement.setIsDel(1);
        vehicleManagement.setCreateUserId(getUserId());
        vehicleManagementService.updateById(vehicleManagement);
        return R.status(true);
    }

}
